import store from "@/store/store";
import axios from "@/utils/request";
import qs from "qs";
/**
 * 读取文章列表
 * @param {object} options
 *
 */
const getList = (options) => {
  return axios.get("/content/list?" + qs.stringify(options));
};
const addArticle = (data) => {
  return axios.post("/content/add", {
    ...data,
  });
};
//编辑文章
const editArticle = (updata) => {
  return axios.post("/content/uparticle", {
    ...updata,
  });
};
//收藏
const setCollect = (collct) => {
  return axios.get("/content/collect?" + qs.stringify(collct));
};
//置顶
const addTop = (data) => {
  return axios.get("/content/totop?" + qs.stringify(data));
};
//加精
const addTags = (tag) => {
  return axios.get("/content/addtag?" + qs.stringify(tag));
};

const getTips = () => {
  return axios.get("/public/tips");
};
//获取本周热议
const getHotWeek = () => {
  return axios.get("/public/topWeek");
};
//广告区域
const getadver = () => {
  return axios.get("/public/adver");
};
const getLinks = () => {
  return axios.get("/public/Links");
};
//图片上传
const uploadImg = (formData) => axios.post("/content/upload", formData);

//获取文章详情
const getDetail = (tid) => {
  let token = store.state.token;
  let headers = {};
  if (token !== "") {
    headers = {
      headers: {
        Authorization: "Bearer " + token,
      },
    };
  }
  return axios.get("/public/content/detail?" + qs.stringify(tid), headers);
};

export {
  getList,
  getTips,
  getLinks,
  getHotWeek,
  uploadImg,
  addArticle,
  getadver,
  getDetail,
  editArticle,
  setCollect,
  addTags,
};
